package com.lineage.server.clientpackets;

import com.lineage.config.ConfigIpCheck;
import com.lineage.echo.ClientExecutor;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ChangeName;
import com.lineage.server.serverpackets.S_PacketBox;
import com.lineage.server.serverpackets.S_PacketBoxIcon1;
import com.lineage.server.serverpackets.S_PacketBoxSelect;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.world.World;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class C_NewCharSelect extends ClientBasePacket {
  private static final Log _log = LogFactory.getLog(C_NewCharSelect.class);
  
  public void start(byte[] decrypt, ClientExecutor client) {
    try {
      if (client.getActiveChar() != null) {
        L1PcInstance pc = client.getActiveChar();
        if (World.get().getPlayer(pc.getName()) == null) {
          client.kick();
        } else if (pc.getOnlineStatus() == 1) {
          pc.sendPackets((ServerBasePacket)new S_ChangeName(pc, false));
          pc.sendPackets((ServerBasePacket)new S_PacketBox(132, pc.getEr()));
          pc.sendPackets((ServerBasePacket)new S_PacketBoxIcon1(true, pc.get_dodge()));
          Thread.sleep(750L);
          client.quitGame();
          client.out().encrypt((ServerBasePacket)new S_PacketBoxSelect());
          _log.info("角色切换: " + pc.getName());
          if (ConfigIpCheck.timeOutSocket != 0) {
            client.SetSocket(ConfigIpCheck.timeOutSocket);
            return;
          } 
          return;
        } 
        return;
      } 
      _log.error("帐号：" + client.getAccountName() + " 空角色退出服务器。");
    } catch (Exception exception) {
    
    } finally {
      over();
    } 
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
